package com.jie.langlangmall.portal.controller;

import com.jie.langlangmall.common.api.CommonPage;
import com.jie.langlangmall.common.api.CommonResult;
import com.jie.langlangmall.portal.domain.MemberProductCollection;
import com.jie.langlangmall.portal.service.MemberCollectionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Jie
 * @Date 2024/11/27
 * @Email 3217998214@qq.com
 * @Description 收藏
 */
@RestController
@Tag(name = "MemberCollectionController", description = "用户收藏管理")
@RequestMapping("/member/productCollection")
public class MemberProductCollectionController {

    @Autowired
    private MemberCollectionService memberCollectionService;

    @Operation(summary = "添加商品收藏")
    @RequestMapping("/add")
    public CommonResult<?> add(@RequestBody MemberProductCollection productCollection) {
        memberCollectionService.add(productCollection);
        return CommonResult.success();
    }

    @Operation(summary = "删除商品收藏")
    @PostMapping("/delete")
    public CommonResult<?> delete(Long productId) {
        memberCollectionService.delete(productId);
        return CommonResult.success();
    }

    @Operation(summary = "显示当前用户商品收藏列表")
    @GetMapping("/list")
    public CommonResult<CommonPage<MemberProductCollection>> list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                  @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        Page<MemberProductCollection> page = memberCollectionService.list(pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @Operation(summary = "显示收藏商品详情")
    @GetMapping("/detail")
    public CommonResult<MemberProductCollection> detail(@RequestParam Long productId) {
        MemberProductCollection memberProductCollection = memberCollectionService.detail(productId);
        return CommonResult.success(memberProductCollection);
    }

    @Operation(summary = "清空收藏列表")
    @PostMapping("/clear")
    public CommonResult<?> clear() {
        memberCollectionService.clear();
        return CommonResult.success();
    }

}
